Skip to content
main
Switch branches/tags
jam0001/Floeckchengrafik/
jam0001/Floeckchengrafik/

Latest commit

* [Add] gitignore

* [Modify] .gitignore

* [Floeckchengrafik] Add initial File Structure and a ToDo List

* [Floeckchengrafik] Change Theme

* [Floeckchengrafik] Add a basic file structure

* [Floeckchengrafik] Add a basic lexer

* [Floeckchengrafik] stuff like new readme, a bit todo and append file dir to pypath

* [Floeckchengrafik] Add Language Tree

* [Floeckchengrafik] Change Language Tree

* [Floeckchengrafik] much parser implementation and start of the node-impl

* [Floeckchengrafik] Change MathNode class name and call the Nodes in the parser

* [Floeckchengrafik] parse var_assign

* [Floeckchengrafik] Working on Executor

* [Floeckchengrafik] 42

* [Floeckchengrafik] Add Function Nodes and create second test

* [Floeckchengrafik] Run Functions but you cant define them

* [Floeckchengrafik] Add Function Nodes to Executor and add Generic Node from which all nodes inherit

* [Floeckchengrafik] Change sample files

* [Floeckchengrafik] Add internals and use (at the moment not first-class) beta comments

* [Floeckchengrafik] WHY THE HELL is readin printed twice?

* Remove Multiline Comments because they dont work

* [Floeckchengrafik] ah, thats why. Readline impl

* [Floeckchengrafik] Working onf Function execution

* [Floeckchengrafik] this error...

* [Floeckchengrafik] ...is resolved

* [Floeckchengrafik] now goes me a light up

* [Floeckchengrafik] Hello World, fix some bugs, Strings and Subtraction now working

* [Floeckchengrafik] Out() testing and new nice format stuff

* [Floeckchengrafik] Fix comments and comment on the examples

* [Floeckchengrafik] Add Basic CLI Interpreter

* [Floeckchengrafik] Add empty lists and length().

* [Floeckchengrafik] Working on if statements

* [Floeckchengrafik] IF

* [Floeckchengrafik] IF #todo

* [Floeckchengrafik] Implement exit() and cleanup internals.py

* [Floeckchengrafik] Reformatted Code

* [Floeckchengrafik] Add For Loops

* [Floeckchengrafik] ["L", "I", "S", "T", "S"]

* [Floeckchengrafik] For remake and intrange + intrange_inclusive

* [Floeckchengrafik] ah yes the format go brr

* [Floeckchengrafik] Editing the ToDo

* [Floeckchengrafik] Working on Doc Strings

* [Floeckchengrafik] Every comment gets its function

* [Floeckchengrafik] Edit the example for a correct comment syntax

* [Floeckchengrafik] Working on Doc Strings

* [Floeckchengrafik] List Get and Set (A mistake of the example...)

* [Floeckchengrafik] Clear ToDoS in executor.py

* [Floeckchengrafik] Reformat examples, Cannot execute StoredProcedures currently

* [Floeckchengrafik] Could only execute if it should return a value. Fixed now

* [Floeckchengrafik] mark the classes-implementation fat

* [Floeckchengrafik] fix an issue in the todo list

* [Floeckchengrafik] compile

* [Floeckchengrafik] Edit README.md

* [Floeckchengrafik] Change examples

* [Floeckchengrafik] Started Documenting Code

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* [Floeckchengrafik] parse classes

* [Floeckchengrafik] Create a new example for classes

* [Floeckchengrafik] Working on Class Implementation

* [Floeckchengrafik] The Error: environments

* [Floeckchengrafik] A bit more debugging

* [Floeckchengrafik] Working on Class Implementation

* [Floeckchengrafik] Fix empty lines bug

* [Floeckchengrafik] Add None to lexer

* add None, fixed merge errors

* [Floeckchengrafik] Add None to lexer

* [Floeckchengrafik] Complete Rewrite of the class-system, does not work yet

* [Floeckchengrafik] Add String internal builtins and update documenta

* [Floeckchengrafik] Class implementation

* [Floeckchengrafik] Change Readme

* [Floeckchengrafik] Add String examples and fix spelling error

* [Floeckchengrafik] Add true and false tokens

* [Floeckchengrafik] Add sleep(millis)

* [Floeckchengrafik] Make sleep var to millis

* [Floeckchengrafik] Remove "Begin" and "End" Execution

* [Floeckchengrafik] Add While Loop

* [Floeckchengrafik] Add string_contains method

* [Floeckchengrafik] Supress warns

* [Floeckchengrafik] Change comment at the forever example

* [Floeckchengrafik] Update Documentation

* Update README.md

* Update README.md

* [Floeckchengrafik] Add Error Handling for variables

* Update README.md

* Update README.md

* Update README.md

* [Floeckchengrafik] Add Binary Operators ||, && and !!

* Update README.md

* Update README.md

* [Floeckchengrafik] Fix error with false class call

* [Floeckchengrafik] Correct line counting

* [Floeckchengrafik] Sokoban. Render Gamefield, player and movtiles. Cannot win or move tiles

* [Floeckchengrafik] use ascii char for target

* [Floeckchengrafik] win

* Update README.md

* [Floeckchengrafik] Add uminus and binary Predecence

* [Floeckchengrafik] Modify Readme

* [Floeckchengrafik] Remove UMINUS

* [Floeckchengrafik] Cant move tiles against walls

* [Floeckchengrafik] move tiles

* [Floeckchengrafik] Check Tiles behind Tiles

* [Floeckchengrafik] Fix Tiles behind Tiles

* [Floeckchengrafik] Final Commit, final README tweaks

Co-authored-by: Flo-Mit-H <flogamesg@gmail.com>
Co-authored-by: Florian Sandmann <72268408+Flo-Mit-H@users.noreply.github.com>
d329f9f

Git stats

Files

Permalink
Failed to load latest commit information.

Comstruct

The Constructor is named comment / Probably some other things too

Content

  1. Compiling the Interpreter
  2. Starting the Interpreter
  3. Variable Assignment
  4. Variable calling
  5. Arithmetic operations
  6. Function Definition
  7. Function Calling
  8. For Loops
  9. Forever Loops
  10. If Statements
  11. Internal Functions
  12. Booleans
  13. Classes
  14. Comments and Function Signatures
  15. Examples

Compiling the Interpreter

You can compile the interpreter into a single executable, but you don't have to. You can either execute the comstruct.py file from the src-directory or the built binary in dist/.

On (pretty much) any sytem with python 3.9 and all the requirements installed, in (pretty much) any shell go to the Floeckchengrafik/src folder of the cloned repo and run pyinstaller comstruct.py application_stack_utils.py executor.py internals.py lexer.py parser.py -c -F -p . --distpath ../dist --collect-all sly .

We have no idea if it'll run on other platforms too. We (Chris and Flo) both use arch btw. If you have any suggestions or tests for other platforms, we'll be happy to add them to this readme. Don't hesitate to open an issue on this repo.

Starting the Interpreter

If you compiled the Interpreter, you can run the binary file in dist/ like this: ./comstruct example.cmstr
If not, you can run python src/comstruct.py example.cmstr.
Of course, replace example.cmstr with whatever your filename is. When you don´t have a .cmstr file to execute, you can also run ./comstruct in dist/ or python comstruct.py in src to get to the repl.

Code Documentation

Basics

Variable assignment:

Format Example
<name> = <assignment>? foo = 1?

Variable calling:

Format Example
<name>? foo?

Note: variables can also be used in arithmetic operations, e.g. 1 + x - y?

Arithmetic Operations:

Format Example
<var1> <operation> <var2>? 1 + 1?

Note: operation can be one of the following characters: +, -, *, /, %

Function Definition:

Format Example
<name> = function({ /* function body */ })? foo = function({out("I am here!!1!")?})?

Function Calling:

Format Example
<name>([args])? foo()?

For Loops:

Format Example
for("<name>" : <operation> : { /* loop body */ })? for ("x" : intrange(0:20) : { out("This is test nr. " : y)? })?

Forever Loops:

Format Example
forever({ /* loop body */ })? forever ({ out("This Loop will run infinite")? })?

If Statements:

Format Example
if(<condition> : { /* statement body */ }? if (1 == 1 : {out("1 is 1!")? })?

In If Statements you can use following operators for your operation: ==, !=, <, <=, >, >=, &&, ||, !!

Internal Functions:

out()

  • prints something to the console
  • args:
    1. The message that should be printed in the console

readline()

  • reads userinput from the console
  • args:
    1. The Message that should stand in front of the user´s cursor

length()

  • gets the length of a list
  • args:
    1. the list of which the length should be returned

list_add()

  • adds an element to a list
  • args:
    1. The object that should be appended to the list
    2. The list the object should be appended to

list_clear()

  • clears the list
  • args:
    1. The list that should be cleared

list_extend()

  • Extends the list with the given item
  • args:
    1. The list that should be extended
    2. The element that the list should be extended with

list_pop()

  • Takes out the given element of the list, when nothing is given, it pops the first element
  • args:
    1. The list from which the element should be popped
    2. [Optional] The element that should be popped

list_reverse()

  • Reverses the given list
  • args:
    1. The list that should be reversed

list_sort()

  • Sorts the list
  • args:
    1. The list that should be sorted

list_get()

  • Gets an element from a list
  • args:
    1. The list from which the element should be taken
    2. The element index that should be taken

list_set()

  • Sets an element of a list
  • args:
    1. The list in which the element should be inserted / replaced
    2. The element index that should be inserted / replaced
    3. The insertment / replacement

intrange()

  • returns a list of integers
  • args:
    1. The minimum (inclusive)
    2. The maximum (exclusive)

intrange_inclusive()

  • returns a list of integers
  • args:
    1. The minmum (inclusive)
    2. The maximum (inclusive)

string_startswith()

  • Checks if the string starts with a given prefix
  • args:
    1. The string to check
    2. The prefix

string_endswith()

  • Checks if the string ends in a given suffix
  • args:
    1. The string to check
    2. The suffix

string_islower()

  • Checks if the string is lowercase
  • args:
    1. The string to check

string_isupper()

  • Checks if the string is uppercase
  • args:
    1. The string to check

string_lower()

  • Sets a string to lowercase
  • args:
    1. The string to change

string_upper()

  • Sets a string to uppercase
  • args:
    1. The string to change

string_removeprefix()

  • Removes a given prefix of a string
  • args:
    1. The string to change
    2. the prefix to remove

string_removesuffix()

  • Removes a given suffix of a string
  • args:
    1. The string to change
    2. The suffix to remove

string_replace()

  • Replaces something in a string with something else
  • args:
    1. The String to change
    2. The old string
    3. The replacement string

string_split()

  • Splits a string by the given characters
  • args:
  1. The string to split
  2. The separator

string_contains()

  • Splits a string by the given characters
  • args:
  1. The string to check
  2. The part string

None

None is the keyword for a non-existing Value, equal to null in other languages

Booleans

true

false

A boolean is a value that could be either true or false

Classes

Format Example
<name> = class({ /* class body */})? foo = class({ comment = function({ out("Hello World")? })? })?

To Instance a class, use <name>([args])?
To run a class method, use <class_instance_name>.<method_name>([args])?

Constructors

You define a constructor using comment = function ({ /* Constructor body here */ })?. You name the constructor comment, because the theme of this jam is "first-class-comments", and the constructor is the first thing that gets executed in a class.

Comments and Function Signatures

For a single-line-comment, write \\ To start a multi-line-comment, write /*. To end it, write */

Function Signatures are needed when you want to pass a variable to a class or method. You can start a Function Signature with /* and end it with */.

To pass an argument to a class / function, you write - param <name> in a new line. To allow a return value from the function, you write - return in a new line. The last statement in the function will be evaluated and returned.

Examples

In this repo, there are 9 examples:

If you have any ideas for other examples, just create an issue or a pullrequest.